package com.youaishujuhui.devops.web.domain.host;

import java.util.Date;

import org.nutz.dao.entity.annotation.ColDefine;
import org.nutz.dao.entity.annotation.ColType;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Comment;
import org.nutz.dao.entity.annotation.Default;
import org.nutz.dao.entity.annotation.EL;
import org.nutz.dao.entity.annotation.Id;
import org.nutz.dao.entity.annotation.Index;
import org.nutz.dao.entity.annotation.One;
import org.nutz.dao.entity.annotation.Prev;
import org.nutz.dao.entity.annotation.Table;
import org.nutz.dao.entity.annotation.TableIndexes;

import com.alibaba.druid.util.StringUtils;
import com.youaishujuhui.devops.web.domain.game.Game;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Table("t_host")
@TableIndexes({@Index(name="idx_ctccIp",fields={"ctccIp"},unique = true),
	@Index(name="idx_cuccIp",fields={"cuccIp"},unique = true),
	@Index(name="idx_cmccIp",fields={"cmccIp"},unique = true)})
@Getter
@Setter
@ToString
public class Host {
	
	@Id
	@Comment("主机id")
	private int hostId;
	
	@Column
	@ColDefine(notNull = true)
	@Comment("关联的游戏id")
	private int gameId;
	
	@One(field = "gameId")
	private Game game;
	
	@Column
	@ColDefine(notNull = true, width = 50)
	@Comment("出机方（相当于大渠道，看怎么关联上大渠道）")
	private String property;
	
	@Column
	@ColDefine(notNull = true, width = 50)
	@Comment("机房（维护一个表）")
	private String idc;
	
	// 机柜（关联机房），

	@Column
	@ColDefine(notNull = true, width = 50)
	@Comment("地区（相当于游戏版本，看怎么关联上游戏版本）")
	private String area;
	
	@Column
	@ColDefine(width = 50)
	@Comment("电信ip")
	private String ctccIp;
	
	@Column
	@ColDefine(width = 50)
	@Comment("联通ip")
	private String cuccIp;
	
	@Column
	@ColDefine(width = 50)
	@Comment("移动ip")
	private String cmccIp;
	
	@Column
	@ColDefine(notNull = true, width = 50)
	@Comment("局域网ip")
	private String lanIp;
	
	@Column
	@ColDefine(notNull = true)
	@Comment("ssh端口号")
	private int sshPort;
	
	@Column
	@ColDefine(notNull = true)
	@Default("0")
	@Comment("目前已装服的数量")
	private int curGameServerCount;
	
	@Column
	@ColDefine(notNull = true)
	@Default("1")
	@Comment("最大游戏数（暂时不用，16G内存填2,32G填4,64G填8）")
	private int maxGameServerCount;
	
	@Column
	@ColDefine(notNull = true)
	@Comment("角色")
	private int role;
	
	@Column
	@ColDefine(notNull = true)
	@Default("0")
	@Comment("状态(上架:1;下架:0;已删除:-1;已初始化：-2;未初始化：-3;)")
	private int state;
	
	@Column
	@ColDefine(type = ColType.TEXT)
	@Comment("备注")
	private String remark;
	
    @Column
    @Prev(els = @EL("now()"))
    @Comment("安装时间")
    private Date createTime;
	
	public String getAvailablePublicIp() {
		if (!StringUtils.isEmpty(getCtccIp())) {
			return getCtccIp();
		}
		
		if (!StringUtils.isEmpty(getCuccIp())) {
			return getCuccIp();
		}
		
		if (!StringUtils.isEmpty(getCmccIp())) {
			return getCmccIp();
		}
		
		return null;
	}
}
